package com.songtech.product.service.impl;

import com.songtech.common.dictionary.dao.SysDictionaryGroupMapper;
import com.songtech.common.dictionary.dao.SysDictionaryMapper;
import com.songtech.product.bean.Product;
import com.songtech.product.dao.ProductMapper;
import com.songtech.product.service.ProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ProductServiceImpl implements ProductService{

    @Resource
    private ProductMapper productMapper;

    @Resource
    private SysDictionaryGroupMapper sysDictionaryGroupMapper;

    @Resource
    private SysDictionaryMapper sysDictionaryMapper;

    @Override
    public List<Product> getProduct(Map<String,String> map) {

        List<Product> list=productMapper.getProduct(map);
        if (list!=null){
            list.forEach(l->{
                l.setVender(sysDictionaryGroupMapper.selectNameById(l.getCompanyCode()));
                l.setProduct(sysDictionaryMapper.selectNameById(l.getProductCode()));
                l.setVersion(sysDictionaryMapper.selectNameById(l.getModelNumber()));
            });
        }
        return list;
    }

    @Override
    public int updateByPrimaryKeySelective(Product product) {
        return productMapper.updateByPrimaryKeySelective(product);
    }

    @Override
    public Product getProductByImei(String imei) {
        return productMapper.getProductByImei(imei);
    }

    @Override
    public int importPic(Product product) {
        return 0;
    }
}
